package com.atguigu.day22.work;

import org.junit.Test;

import java.io.File;
import java.io.FileFilter;
import java.util.ArrayList;

public class Work8 {
    @Test
    public void w1(){
        File f1=new File("d:/atguigu");
        File[] files=f1.listFiles(new FileFilter() {
            @Override
            public boolean accept(File pathname) {
                return pathname.getName().endsWith(".java");
            }
        });
        for (File file : files) {
            System.out.println(file);
        }
    }
    @Test
    public void w2(){
        File f1=new File("d:/atguigu");
        ArrayList<String> all=listAllSubs(f1);
        for (String s : all) {
            System.out.println(s);
        }
    }
    public ArrayList<String> listAllSubs(File file){
        ArrayList<String> list=new ArrayList<>();
        if (file.isFile()){
            if(file.getName().endsWith(".java")){
                list.add(file.getPath());
            }
        }else if(file.isDirectory()){
            File[] listFiles=file.listFiles();
            for (File listFile : listFiles) {
                list.addAll(listAllSubs(listFile));
            }
        }
        return list;
    }
}
